package com.yingxue.lesson.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

/**
 * 注册三大组件配置类
 */
@Configuration
public class ServletConfig {


//    @Bean
//    public CrossOriginFilter crossOriginFilter(){
//        return new CrossOriginFilter();
//    }

    /**
     * 注册 处理跨域问题 过滤器
     */
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        //CrossOriginFilter crossOriginFilter = new CrossOriginFilter();
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        //设置过滤器
        filterRegistrationBean.setFilter(new CrossOriginFilter());
        //设置拦截路径
        filterRegistrationBean.addUrlPatterns("/api/*");
        //设置名称
        filterRegistrationBean.setName("CrossOriginFilter");
        return filterRegistrationBean;
    }

}
